package com.example.itshome.activity;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.bumptech.glide.Glide;
import com.example.itshome.R;
import com.example.itshome.network.AbstractNetworkRequest;
import com.example.itshome.network.SignUpActivityRequest;

public class ActivityParticularActivity extends AppCompatActivity {

    private ImageView backImageView;
    private ImageView imageView;
    private TextView nameTextView;
    private TextView timeTextView;
    private TextView locateTextView;
    private TextView introductionTextView;
    private Button signUpButton;
    private String[] data;
    private int activityId;
    private boolean isSignUp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_activity_particular);
        initFind();
        initButton();
        initView();
    }

    void initFind(){
        backImageView=findViewById(R.id.imv_activity_particular_page_back);
        imageView=findViewById(R.id.imv_activity_particular_page_image);
        nameTextView=findViewById(R.id.txv_activity_particular_page_topic);
        introductionTextView=findViewById(R.id.txv_activity_particular_page_introduction);
        timeTextView=findViewById(R.id.txv_activity_particular_page_time);
        locateTextView=findViewById(R.id.txv_activity_particular_page_locate);
        signUpButton=findViewById(R.id.btn_activity_particular_page_sign_up);
    }

    void initButton(){
        backImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        signUpButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AbstractNetworkRequest request=new SignUpActivityRequest(ActivityParticularActivity.this)
                        .setActivityId(activityId)
                        .setSignUpButton(signUpButton);
                request.start();
            }
        });
    }

    void initView(){
        Intent intent=getIntent();
        data=intent.getStringArrayExtra("data");
        nameTextView.setText(data[0]);
        timeTextView.setText(data[1]);
        locateTextView.setText(data[2]);
        introductionTextView.setText(data[3]);
        activityId=intent.getIntExtra("activityId",-1);
        isSignUp=intent.getBooleanExtra("isSignUp",false);
        signUpButton.setClickable(!isSignUp);
        signUpButton.setText(isSignUp?"已报名":"报名");
        Glide.with(this).load(data[4]).placeholder(R.drawable.sample_picture).into(imageView);
    }
}